<template>
	<!-- 收藏夹 -->
	<view class="collet">
		<view v-if="exist">
			<view class="collet-item" v-for="(item,index) in dataList" :key="index" >
				<view class="it-l" @click="navTo(item.proid)">
					<image :src="item.proimgs" mode="aspectFill"></image>
				</view>
				<view class="it-r">
					<image :src="item.shavatar" mode="aspectFill"></image>
					<text class="line1-text2 font30" @click="toStoreDetail(item.shid)">{{item.shname}} <text class="iconfont">&#xe600;</text></text>
					<view class="r-title">
						{{item.proname}}
					</view>
					<view class="m-collet">
						{{item.pro_collect_nums}}人收藏
					</view>
					<view class="f-content">
						<view class="">
							<text>￥{{item.nowprice}}</text>
						</view>
						<view class="delBtn">
							<text @click="del(index,item.proid)">删除</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 缺省页 start-->
		<view class="default-page" v-else>
			<image src="/static/imgs/defaultPage/shouchangjia.png" mode="aspectFill"></image>
			<view>
				收藏夹空空如也，快去转转吧~
			</view>
			<view class="button">
				<button @click="switchTab('/pages/index/index')">首页</button>
			</view>
		</view>
		<!-- 缺省页 end-->
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [], // 数据列表
				exist: true, // 缺省状态控制
			};
		},
		onPullDownRefresh() {
			this.getData();
		},
		onLoad() {
			this.getData();
		},
		methods:{
			async getData(){
				let a = await this.$http.getCollect();
				this.dataList = a.data;
				a.data.length == 0 ? this.exist = false : this.exist = true;
				uni.stopPullDownRefresh();
			},
			async del(index,id){
				let a = await this.$http.deleteCollect({proid: id})
				if(a.code == 200) {
					this.dataList.splice(index, 1);
					this.dataList.length == 0 ? this.exist = false : this.exist = true;
					uni.showToast({
						title: "删除商品收藏成功~~",
						icon: 'none'
					});
					return
				}
				uni.showToast({
					title: a.message,
					icon: 'none'
				});
			},
			navTo(id){ // 去详情界面
				uni.navigateTo({
					url: `/pages/detail/detail?proid=${id}`
				})
			},
			toStoreDetail(id){
				uni.navigateTo({ // 缺店铺ID
				// shid
					url: `/pages/user/storedetails?shid=${id}`
				})
			},
			switchTab(url) {
				uni.switchTab({
					url
				})
			},
		}
	}
</script>

<style lang="scss" >
@import 'static/css/smallCommon.scss';
</style>
